feat: P0-4 工具执行期引入 WorkspacePlan 以收敛 TOCTOU 风险#138
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
基于 issue #122(P0-4)落地工具执行期 TOCTOU 防护,目标是在不改动主链路分层(TUI -> Runtime -> Provider -> Tools)的前提下,把 sandbox 校验结果绑定到执行期消费。
Closes #122
本次改动
WorkspaceSandbox.Check从“仅返回 error”升级为“返回*WorkspaceExecutionPlan”。ToolCallInput新增WorkspacePlan,由ToolManager透传到工具执行层。tools.ResolveWorkspaceTarget(...),统一在工具层消费执行计划并做执行前复验。filesystem_read_file/filesystem_write_file/filesystem_edit/bash全部接入执行计划。WorkspaceExecutionPlan.ValidateForExecution()在执行前复验 anchor 路径与快照,识别校验后替换(TOCTOU)场景。docs/tool-execution-toctou.md,说明防护边界与剩余限制。测试补充
internal/tools/manager_toctou_test.go:internal/tools/workspace_plan_test.go:internal/security/workspace_test.go:ValidateForExecution()的空值、变更、成功路径capturePathSnapshot()常规/符号链接/异常路径pathSnapshot.Equal()等价与差异分支internal/tools/bash/tool_test.go:call.Workdir为空时回退到工具 root 的执行路径验证结果
go test ./... -count=1✅go test ./... -covermode=atomic -coverprofile=F:/Qiniu/neo-code/coverage.out -count=1✅87.5%(go tool cover -func F:/Qiniu/neo-code/coverage.out)风险与限制
openat/no-follow/dirfd级别的原子系统调用封装。